package com.westvalley.tools.excel.annotation;

import java.lang.reflect.Field;
import java.util.List;


import com.google.common.collect.Lists;
import com.westvalley.common.kit.StringKit;

public class FieldTitleHelp {
	public static String getFieldText(Field field){
		FieldTitle fieldTitle = field.getAnnotation(FieldTitle.class);
		if(fieldTitle!=null){
			return fieldTitle.text();
		}
		return null;
	}
	
	public static <T> List<Object> getFieldTexts(Class<T> clazz){
		List<Object> list = Lists.newArrayList();
		if(clazz!=null){
			for(Field field : clazz.getDeclaredFields()){
				String text = StringKit.null2Str(getFieldText(field));
				if(!"".equals(text)){
					list.add(text);
				}
			}
		}
		return list;
	}
	
	public static List<String> getAnnotationFields(Class<?> clazz){
		List<String> list = Lists.newArrayList();
		for(Field field : clazz.getDeclaredFields()){
			FieldTitle fieldTitle = field.getAnnotation(FieldTitle.class);
			if(fieldTitle!=null){
				list.add(field.getName());
			}
		}
		return list;
	}
	
	public static List<Field> getAnnotationFieldObjects(Class<?> clazz){
		List<Field> list = Lists.newArrayList();
		if(clazz!=null){
			for(Field field : clazz.getDeclaredFields()){
				FieldTitle fieldTitle = field.getAnnotation(FieldTitle.class);
				if(fieldTitle!=null){
					list.add(field);
				}
			}
		}
		return list;
	}
}
